home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / games / uchess / src / dspcom.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  42KB  |  1,837 lines

  1. #define CLEARHISTBETWEENMOVES // old way to handle hist table
  2. /*
  3.  * dspcom.c - C source for GNU CHESS
  4.  *
  5.  * Copyright (c) 1988,1989,1990 John Stanback
  6.  * Copyright (c) 1992 Free Software Foundation
  7.  *
  8.  * This file is part of GNU CHESS.
  9.  *
  10.  * GNU Chess is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * GNU Chess is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with GNU Chess; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24. #include "gnuchess.h"
  25. extern INTSIZE Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  26. extern char *version, *patchlevel;
  27. char __aligned mvstr[4][6];
  28. char __aligned *InPtr;
  29. #define BOOKMENUNUM 0xc2
  30.  
  31. #ifdef CACHE
  32. extern struct etable __far __aligned etab[2][ETABLE];
  33. #endif
  34.  
  35.  
  36. extern unsigned int TTadd;
  37.  
  38. int __aligned SecsPerMove=10;
  39. extern int IllegalMove;
  40. int __aligned func_num=0;
  41. int __aligned thinkahead=0;
  42. int __aligned ThinkInARow=0;
  43. int __aligned ThinkAheadWorked=0;
  44. int __aligned ThinkAheadDepth=0;
  45.  
  46. extern int backsrchaborted;
  47. extern short int ISZERO;
  48. extern short __aligned background;
  49. int __aligned verifyquiet=0;
  50. int __aligned MouseDropped=0;
  51.  
  52. #include <ctype.h>
  53. #include <signal.h>
  54.  
  55. #ifdef AMIGA
  56. #define __USE_SYSBASE
  57. #include <exec/types.h>
  58. #include <exec/exec.h>
  59. #include <proto/exec.h>
  60. #include <proto/dos.h>
  61. #include <proto/graphics.h>
  62. #include <proto/intuition.h>
  63. struct IntuiMessage __aligned globalmessage;
  64. int __aligned globalmessage_valid=0;
  65. extern struct Window __aligned *wG;
  66. extern int procpri;
  67. extern struct Process *myproc;
  68. extern struct MenuItem MenuItem6;
  69. extern struct Menu Menu1;
  70. extern unsigned char __far cookedchar[128];
  71. extern struct Menu __aligned Menu1;
  72. #define MenuList1 Menu1
  73. extern struct MenuItem __aligned MenuItem8ab;
  74. extern int __aligned MenuStripSet;
  75. #endif
  76.  
  77. #define SIGQUIT SIGINT
  78.  
  79. #ifdef MSDOS
  80. #include <dos.h>
  81. #include <conio.h>
  82. #include <stdlib.h>
  83. #include <string.h>
  84. #include <time.h>
  85. #else
  86. #include <dos.h>
  87. #include <stdlib.h>
  88. #include <string.h>
  89. #include <time.h>
  90. /*
  91. #include <sys/param.h>
  92. #include <sys/types.h>
  93. #include <sys/file.h>
  94. #include <sys/ioctl.h>
  95. */
  96. #endif
  97.  
  98.  
  99. /*
  100.  * ataks.h - Header source for GNU CHESS
  101.  *
  102.  * Copyright (c) 1988,1989,1990 John Stanback
  103.  * Copyright (c) 1992 Free Software Foundation
  104.  *
  105.  * This file is part of GNU CHESS.
  106.  *
  107.  * GNU Chess is free software; you can redistribute it and/or modify
  108.  * it under the terms of the GNU General Public License as published by
  109.  * the Free Software Foundation; either version 2, or (at your option)
  110.  * any later version.
  111.  *
  112.  * GNU Chess is distributed in the hope that it will be useful,
  113.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  114.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  115.  * GNU General Public License for more details.
  116.  *
  117.  * You should have received a copy of the GNU General Public License
  118.  * along with GNU Chess; see the file COPYING.  If not, write to
  119.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  120.  */
  121. inline int
  122. SqAtakd2 (ARGSZ int sq, ARGSZ int side)
  123.  
  124. /*
  125.  * See if any piece with color 'side' ataks sq.  First check pawns then
  126.  * Queen, Bishop, Rook and King and last Knight.
  127.  */
  128.  
  129. {
  130.   register INTSIZE u;
  131.   register unsigned char *ppos, *pdir;
  132.   INTSIZE xside;
  133.  
  134.   xside = side ^ 1;
  135.   pdir = nextdir[ptype[xside][pawn]][sq];
  136.   u = pdir[sq];            /* follow captures thread */
  137.   if (u != sq)
  138.     {
  139.       if (board[u] == pawn && color[u] == side)
  140.     return (true);
  141.       u = pdir[u];
  142.       if (u != sq && board[u] == pawn && color[u] == side)
  143.     return (true);
  144.     }
  145.   /* king capture */
  146.   if (distance (sq, PieceList[side][0]) == 1)
  147.     return (true);
  148.   /* try a queen bishop capture */
  149.   ppos = nextpos[bishop][sq];
  150.   pdir = nextdir[bishop][sq];
  151.   u = ppos[sq];
  152.   do
  153.     {
  154.       if (color[u] == neutral)
  155.     u = ppos[u];
  156.       else
  157.     {
  158.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  159.         return (true);
  160.       u = pdir[u];
  161.     }
  162.   } while (u != sq);
  163.   /* try a queen rook capture */
  164.   ppos = nextpos[rook][sq];
  165.   pdir = nextdir[rook][sq];
  166.   u = ppos[sq];
  167.   do
  168.     {
  169.       if (color[u] == neutral)
  170.     u = ppos[u];
  171.       else
  172.     {
  173.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  174.         return (true);
  175.       u = pdir[u];
  176.     }
  177.   } while (u != sq);
  178.   /* try a knight capture */
  179.   pdir = nextdir[knight][sq];
  180.   u = pdir[sq];
  181.   do
  182.     {
  183.       if (color[u] == side && board[u] == knight)
  184.     return (true);
  185.       u = pdir[u];
  186.   } while (u != sq);
  187.   return (false);
  188. }
  189.  
  190.  
  191. void
  192. algbr (INTSIZE int f, INTSIZE int t, INTSIZE int flag)
  193.  
  194.  
  195. /*
  196.  * Generate move strings in different formats.
  197.  */
  198.  
  199. {
  200.   int m3p;
  201.  
  202.   if (f != t)
  203.     {
  204.       /* algebraic notation */
  205.       mvstr[0][0] = cxx[column (f)];
  206.       mvstr[0][1] = rxx[row (f)];
  207.       mvstr[0][2] = cxx[column (t)];
  208.       mvstr[0][3] = rxx[row (t)];
  209.       mvstr[0][4] = mvstr[3][0] = '\0';
  210.       if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  211.     {
  212.       if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  213.         {
  214.           mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  215.           mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  216.           m3p = 2;
  217.         }
  218.       else
  219.         /* pawn ate */
  220.         {
  221.           mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* column */
  222.           mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  223.           mvstr[2][2] = mvstr[0][3];
  224.           m3p = 3;        /* to row */
  225.         }
  226.       if (flag & promote)
  227.         {
  228.           mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  229.           mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  230. #ifdef CHESSTOOL
  231.           mvstr[3][0] = mvstr[0][0];    /* Allow e7e8 for chesstool */
  232.           mvstr[3][1] = mvstr[0][1];
  233.           mvstr[3][2] = mvstr[0][2];
  234.           mvstr[3][3] = mvstr[0][3];
  235.           mvstr[3][4] = '\0';
  236. #endif
  237.         }
  238.       mvstr[2][m3p] = mvstr[1][2] = '\0';
  239.     }
  240.       else
  241.     /* not a pawn */
  242.     {
  243.       mvstr[2][0] = mvstr[1][0];
  244.       mvstr[2][1] = mvstr[0][1];
  245.       mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  246.       mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  247.       mvstr[2][4] = mvstr[1][3] = '\0';
  248.       strcpy (mvstr[3], mvstr[2]);
  249.       mvstr[3][1] = mvstr[0][0];
  250.       if (flag & cstlmask)
  251.         {
  252.           if (t > f)
  253.         {
  254.           strcpy (mvstr[1], CP[5]);
  255.           strcpy (mvstr[2], CP[7]);
  256.         }
  257.           else
  258.         {
  259.           strcpy (mvstr[1], CP[6]);
  260.           strcpy (mvstr[2], CP[8]);
  261.         }
  262.         }
  263.     }
  264.     }
  265.   else
  266.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  267. }
  268.  
  269.  
  270. int
  271. VerifyMove (char *s, INTSIZE int iop, INTSIZE unsigned int *mv)
  272.  
  273. /*
  274.  * Compare the string 's' to the list of legal moves available for the
  275.  * opponent. If a match is found, make the move on the board.
  276.  */
  277.  
  278. {
  279.   static INTSIZE pnt, tempb, tempc, tempsf, tempst, cnt;
  280.   int r,c,l;
  281.   char mystr[80];
  282.   char piece;
  283.   static struct leaf xnode;
  284.   struct leaf *node;
  285.  
  286.   if ((s[1] >= 'a') && (s[1] <= 'h'))
  287.    {
  288.     if ((s[0] == 'n') || (s[0] == 'p') || (s[0] == 'b') ||
  289.         (s[0] == 'k') || (s[0] == 'r') || (s[0] == 'q'))
  290.      {
  291.       s[0] = toupper(s[0]);
  292.      }
  293.    }
  294.   *mv = 0;
  295.   if (iop == 2)
  296.     {
  297.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  298.       return (false);
  299.     }
  300.   cnt = 0;
  301.   MoveList (opponent, 2);
  302.   pnt = TrPnt[2];
  303.   while (pnt < TrPnt[3])
  304.     {
  305.       node = &Tree[pnt++];
  306.       algbr (node->f, node->t, (INTSIZE) node->flags);
  307.       if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  308.       strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
  309.     {
  310.       cnt++;
  311.       xnode = *node;
  312.     }
  313.     }
  314.   if (cnt == 1)
  315.     {
  316.       MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  317.       if (SqAtakd2 (PieceList[opponent][0], computer))
  318.     {
  319.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  320. #if defined CHESSTOOL
  321.       printz (CP[15]);
  322. #else
  323. #ifdef NONDSP
  324. /* Illegal move in check */
  325. #ifndef AM